package com.qdxwx.captcha.text.impl;

import com.qdxwx.captcha.text.TextProducer;
import com.qdxwx.captcha.util.Configurable;

import java.util.Random;

public class DefaultTextCreator extends Configurable implements TextProducer
{
    /**
     * @return the random text
     */
    public String getText()
    {
        int length = getConfig().getTextProducerCharLength();
        char[] chars = getConfig().getTextProducerCharString();
        Random rand = new Random();
        StringBuilder text = new StringBuilder();
        for (int i = 0; i < length; i++)
        {
            text.append(chars[rand.nextInt(chars.length)]);
        }

        return text.toString();
    }
}
